var app = getApp();
var _DB = require('../../../utils/db.js')
var studentID = app.globalData.studentID;

Page({

  data: {
    inoutList:[],
  },

  onLoad: function (options) {
    wx.showToast({
      title: '努力获取中',
      icon: 'loading',
      mask: true
    })
    const _this = this;
    console.log(studentID)
    _DB.getInOutByid(studentID,function(res){
      console.log(res)
      var inoutList = _this.doList(res);
      _this.setData({ inoutList: inoutList })
    })
    
  },

  //处理数组
  doList: function (list) {
    var timestamp;
    var identity;
    var inout;
    for (var i = 0; i < list.length; i++) {
      list[i].timestamp = this.doTime(list[i].timestamp);
      list[i].inorout = this.doInout(list[i].inorout);
    }
    return list.reverse();
  },
  //时间戳转换
  doTime: function (timestamp) {
    var date = new Date(timestamp * 1000);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate(); d = d < 10 ? ('0' + d) : d;
    var h = date.getHours(); h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds(); minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return m + '/' + d + ' ' + h + ':' + minute;
  },
  //进出转换
  doInout: function (inout) {
    if (inout == 0) {
      return "正门进校";
    } else if (inout == 1) {
      return "正门出校";
    } else if (inout == 2) {
      return "南门进校";
    } else if (inout == 3) {
      return "南门出校";
    }
  },

})